package com.example.administrator.mynaozhong;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Switch;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/1/5.
 */
public class SheZhiActivity extends AppCompatActivity {

    private Button quxiao, queding;
    private Context context;
    public static SimpleAdapter adapter;
    ArrayList<Map<String, String>> list = new ArrayList<>();

    public static String  selectedDateStr = "";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shezhi);

        Toast.makeText(SheZhiActivity.this, "intointointo！", Toast.LENGTH_SHORT).show();Log.d("============>", "");
        ListView listView = (ListView) findViewById(R.id.list1);



        Map map = new HashMap();
        map.put("da", "重复");
        map.put("xiao",SheZhiActivity.selectedDateStr);
        list.add(map);

        Map map1 = new HashMap();
        map1.put("da", "铃声");
        map1.put("xiao", "皇甫嵩里");
        list.add(map1);

        Map map2 = new HashMap();
        map2.put("da", "振动");
        map2.put("xiao", "响铃时振动");
        list.add(map2);


        adapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, new String[]{"da", "xiao"},
                new int[]{android.R.id.text1, android.R.id.text2});
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                if (position == 0) {

                    Intent i = new Intent(SheZhiActivity.this, SheZhi1Activity.class);

                    startActivity(i);

                } else if (position == 1) {

                    // 打开系统铃声设置
                    Intent intent = new Intent(
                            RingtoneManager.ACTION_RINGTONE_PICKER);
                    // 设置铃声类型和title
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                            RingtoneManager.TYPE_ALARM);
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "null");
                    // 当设置完成之后返回到当前的Activity
                    startActivityForResult(intent, SheZhiActivity.CONTEXT_INCLUDE_CODE);
                } else if (position == 2){


                }
            }
        });


        quxiao = (Button) findViewById(R.id.quxiao);
        quxiao.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(SheZhiActivity.this, MainActivity.class);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(SheZhiActivity.this, 0, intent, 0);
                startActivity(intent);
                //获取闹钟管理器
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.cancel(pendingIntent);
                Toast.makeText(SheZhiActivity.this, "闹钟已经取消！", Toast.LENGTH_SHORT).show();
            }
        });


        queding = (Button) findViewById(R.id.queding);
        queding.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(SheZhiActivity.this, MainActivity.class);
                startActivity(intent);
                //获取闹钟管理器
                Toast.makeText(SheZhiActivity.this, "已经添加闹钟！", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        HashMap<String,String>map = (HashMap<String,String>)list.get(0);
        map.put("xiao", SheZhiActivity.selectedDateStr);

        adapter.notifyDataSetChanged();

        Toast.makeText(SheZhiActivity.this, "resume resume！", Toast.LENGTH_SHORT).show();
    }
}
